﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Configuration;

namespace NuGet.Enterprise.Server.Configuration
{
    public class BuildStoreConnectionProxy
        : ConfigurationElement
    {
        public BuildStoreConnectionSettings Instance
        { get; private set; }

        public string Name
        {
            get { return (this.Instance == null ? null : this.Instance.Name); }
        }

        protected override void DeserializeElement(System.Xml.XmlReader reader, bool serializeCollectionKey)
        {
            BuildStoreConnectionType type;

            if (Enum.TryParse<BuildStoreConnectionType>(reader.GetAttribute("type"), true, out type))
            {
                switch (type)
                {
                    case BuildStoreConnectionType.TeamBuildDefinition:

                        this.Instance = new TeamBuildDefinitionConnection();

                        break;

                    case BuildStoreConnectionType.TeamProjectCollection:

                        this.Instance = new TeamProjectCollectionConnection();

                        break;
                }
            }

            if (this.Instance != null)
            {
                this.Instance.DeserializeElementInternal(reader, serializeCollectionKey);
            }
        }
    }
}